package com.hfjava.practice02;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Scanner;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: com.hfjava.practice02
 * @ClassName: WorldCup
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/12/24 18:35
 * @Copyright 大牛版板所有
 */
public class WorldCup {

    public static void showCup(String year){
        try (BufferedReader br = new BufferedReader(new FileReader("chapter03\\doc\\worldcup.txt"))){
            String line = null;
            System.out.println("读出的数据为：");
            boolean flag = false;
            String cup = null;
            while ((line = br.readLine()) != null){
                System.out.println(line);
                if (year.equals(line.substring(0,4))){
                    flag = true;
                    cup = line.substring(5);
                }
            }
            System.out.println("===========================================");
            if (!flag){
                System.out.println(year+"年没有举办世界冠军！");
            }
            else {
                System.out.println(year+"年世界冠军为："+cup);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("请输入一个年份：");
        String year = input.next();
        showCup(year);
    }
}
